﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SanctusSoftware.Music.ChordSheetEditor.Client;
using Microsoft.Office.Interop.Word;

namespace SanctusSoftware.Music.ChordSheetEditor.Word
{
  public static class RichTextFormatColorHelper
  {

    private static RichTextFormatColor[] _AvailableColors = null;
    public static RichTextFormatColor[] AvailableColors
    {
      get
      {
        if (_AvailableColors == null)
        {
          List<WdColor> tempList = new List<WdColor>();
          foreach (WdColor value in System.Enum.GetValues(typeof(WdColor)))
          {
            tempList.Add(value);
          }
          tempList.Sort();

          var sortedList = from c in tempList
                           orderby c != WdColor.wdColorAutomatic, c.ToString()
                           select c;

          WdColorColorConverter wdColorColorConverter = new WdColorColorConverter();
          WdColorStringConverter wdColorStringConverter = new WdColorStringConverter();

          List<RichTextFormatColor> colorList = new List<RichTextFormatColor>();

          foreach (WdColor wdColor in sortedList)
          {
            System.Windows.Media.Color color = (System.Windows.Media.Color)wdColorColorConverter.Convert(wdColor, typeof(System.Windows.Media.Color), null, null);
            string name = (string)wdColorStringConverter.Convert(wdColor, typeof(string), null, null);
            RichTextFormatColor rtfc = new RichTextFormatColor(name, color, wdColor);
            colorList.Add(rtfc);
          }
          _AvailableColors = colorList.ToArray();
        }
        return _AvailableColors;
      }
    }

  }
}
